/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clienttest;

import clienttest.common.PrintToPdf;
import clienttest.object.CreditCard;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.SimpleDateFormat;
import java.util.List;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author lekhanhduy
 */
public class StaffBankForm extends javax.swing.JFrame {

    private CreditCard creditCard;
    private WindowAdapter windowAdapter;

    /**
     * Creates new form StaffBankForm
     */
    public StaffBankForm() {
        initComponents();
        this.setLocationRelativeTo(null);
        windowAdapter = new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent we) {
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            }
        };
        this.addWindowListener(windowAdapter);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTbPnManage = new javax.swing.JTabbedPane();
        manageCommon1 = new clienttest.ManageCommon();
        jPnHisTrans = new javax.swing.JPanel();
        jScrollPaneHis = new javax.swing.JScrollPane();
        jTblHistory = new javax.swing.JTable();
        jBtnPrintPDF = new javax.swing.JButton();
        jMnbStaffBank = new javax.swing.JMenuBar();
        jMnAccount = new javax.swing.JMenu();
        jMnItLogout = new javax.swing.JMenuItem();
        jMnItChangePass = new javax.swing.JMenuItem();
        jMnIntro = new javax.swing.JMenu();
        jMmITour = new javax.swing.JMenuItem();
        jMnItAuthor = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTbPnManage.addTab("Quản lý chung", manageCommon1);

        jPnHisTrans.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(153, 153, 153), 2));
        jPnHisTrans.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTblHistory.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPaneHis.setViewportView(jTblHistory);

        jPnHisTrans.add(jScrollPaneHis, new org.netbeans.lib.awtextra.AbsoluteConstraints(2, 5, 850, 470));

        jBtnPrintPDF.setText("Xuất file PDF");
        jBtnPrintPDF.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnPrintPDFActionPerformed(evt);
            }
        });
        jPnHisTrans.add(jBtnPrintPDF, new org.netbeans.lib.awtextra.AbsoluteConstraints(730, 480, 120, -1));

        jTbPnManage.addTab("Lịch sử giao dịch", jPnHisTrans);

        getContentPane().add(jTbPnManage, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, -1, -1));

        jMnAccount.setText("Tài khoản");

        jMnItLogout.setText("Đăng xuất");
        jMnItLogout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMnItLogoutActionPerformed(evt);
            }
        });
        jMnAccount.add(jMnItLogout);

        jMnItChangePass.setText("Đổi mật khẩu");
        jMnItChangePass.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMnItChangePassActionPerformed(evt);
            }
        });
        jMnAccount.add(jMnItChangePass);

        jMnbStaffBank.add(jMnAccount);

        jMnIntro.setText("Giới thiệu");

        jMmITour.setText("Hướng dẫn ");
        jMnIntro.add(jMmITour);

        jMnItAuthor.setText("Tác giả");
        jMnIntro.add(jMnItAuthor);

        jMnbStaffBank.add(jMnIntro);

        setJMenuBar(jMnbStaffBank);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMnItLogoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMnItLogoutActionPerformed
        // TODO add your handling code here:
        Login login = new Login(new AcountBank());
        login.setVisible(true);
        login.show();
        this.dispose();
    }//GEN-LAST:event_jMnItLogoutActionPerformed

    private void jMnItChangePassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMnItChangePassActionPerformed
        ChangePassWord changePass = new ChangePassWord();
        changePass.changePass(creditCard);
        changePass.setVisible(true);
        changePass.show();
    }//GEN-LAST:event_jMnItChangePassActionPerformed

    
    public void displayHistory( List<Object[]> data)
    {
        Object[][] temp = new Object[data.size()][6];
        for (int i = 0; i < data.size(); i++) {
            Object[] objects = data.get(i);
            temp[i] = objects;
        }
        jTblHistory.setModel(new javax.swing.table.DefaultTableModel(
                temp,
                new String[]{
                    "Số tài khoản","Loại giao dịch", "Người nhận/gửi", "Ngày giao dịch", "Giờ giao dịch", "Số tiền"
                }));
        jScrollPaneHis.setVisible(true);
        DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
        rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
        jTblHistory.getColumnModel().getColumn(5).setCellRenderer(rightRenderer);
        jTbPnManage.setSelectedIndex(1);
        validate();
    }
    
    private void jBtnPrintPDFActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtnPrintPDFActionPerformed
        // TODO add your handling code here:
         if (jTblHistory.getRowCount() > 0) {
            int selection = JOptionPane.showConfirmDialog(
                    this, "Bạn có muốn in lịch sử không", "Hãy lựa chọn : ", JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE);
            if (selection == JOptionPane.OK_OPTION) {
                String[] head = { "Số tài khoản", "Loại giao dịch", "Người nhận/gửi", "Ngày giao dịch", "Giờ giao dịch", "Số tiền"};
                PrintToPdf print = new PrintToPdf(jTblHistory, head,null);
                SimpleDateFormat dt = new SimpleDateFormat("dd-MM-yyyy");
                String dateFrom = dt.format(manageCommon1.jDateFromDate.getDate());
                String dateTo = dt.format(manageCommon1.jDateToDate.getDate());
                print.printfPDF(dateFrom, dateTo);
            } else if (selection == JOptionPane.CANCEL_OPTION) {
            }
        } else {
            JOptionPane.showMessageDialog(this,
                    "Chưa có dữ liệu để in",
                    "Lỗi in dữ liệu!",
                    JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jBtnPrintPDFActionPerformed

    public void DisplayInfo(CreditCard credit) {
        creditCard = credit;
        if (creditCard != null) {
            manageCommon1.DisplayInfo(credit,this);
        }
    }
   
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(StaffBankForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(StaffBankForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(StaffBankForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(StaffBankForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new StaffBankForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBtnPrintPDF;
    private javax.swing.JMenuItem jMmITour;
    private javax.swing.JMenu jMnAccount;
    private javax.swing.JMenu jMnIntro;
    private javax.swing.JMenuItem jMnItAuthor;
    private javax.swing.JMenuItem jMnItChangePass;
    private javax.swing.JMenuItem jMnItLogout;
    private javax.swing.JMenuBar jMnbStaffBank;
    private javax.swing.JPanel jPnHisTrans;
    private javax.swing.JScrollPane jScrollPaneHis;
    private javax.swing.JTabbedPane jTbPnManage;
    private javax.swing.JTable jTblHistory;
    private clienttest.ManageCommon manageCommon1;
    // End of variables declaration//GEN-END:variables
}
